package com.demo2.service;

import com.demo2.bean.User;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Service;

/**
 * Author wen
 * Date 2022-01-12
 * service注解监听
 */

@Service
public class UserService {

//    实现对队列andy.news的消息监听
    @RabbitListener(queues = "andy.news")
    public void recevie(User user){
        System.out.println("收到消息:"+user);
    }

    @RabbitListener(queues = "test")
    public void recevie01(Message message){
//        获取消息内容
        System.out.println(message.getBody());
//        获取消息头
        System.out.println(message.getMessageProperties());
    }
}
